import { MotaInterface } from "@/mota";
import { ConsumablesInterface } from "@/mota/data/ItemDataUnit";
import PackUtils from "@/mota/utils/HeroUtils/PackUtils";
import { AttackResult } from "@/mota/utils/HeroUtils/AttributeUtils";
import { AttckTypeInfo, BattleInfo } from "@/mota/data/BattleDataUtils";

export type EnemyMapInfo = [BattleInfo, AttckTypeInfo, AttackResult];

export default class YellowDoor implements MotaInterface, ConsumablesInterface {

    public pack!: PackUtils;

    public itemType!: ConsumablesInterface["itemType"];

    public ZIndex: number = 4;

    public constructor() {
    }

    public SetPack: ConsumablesInterface["SetPack"] = async (pack, itemType) => {
        this.pack = pack;
        this.itemType = itemType;
    }

    public Use: ConsumablesInterface["Use"] = async () => {
        const { pack: { hero } } = this;
        const { Mota: { tip, map } } = hero;
        const point = hero.GetFacePoint();
        if (point === undefined) { tip.AddIconMessage("随意门", "非有效单位"); return false; }
        const units = map.GetUnit(point[0], point[1]);
        if (units === undefined) { tip.AddIconMessage("随意门", "非有效单位"); return false; }
        const unit = units[0];
        const event = unit[4];
        if (event === undefined || !event.has("prop")) { tip.AddIconMessage("随意门", "无法对面前的单位使用"); return false; }
        if (unit[0] !== "石墙") { tip.AddIconMessage("随意门", "无法对面前的单位使用"); return false; }
        unit[0] = "黄门";
        unit[3] = "first";
        unit[4] = new Set(<const>["consume"]);
        return false;
    }

}